var listUrl = basePath + "/sys/point/report/teacher/itemList";
var termListUrl = basePath + "/sys/dict/termList";
var dataGrid;
$(function() {
	initDatebox();
	initTermList();
	initSubjectList();
	initGradeList();
});
function loadData() {
	dataGrid = $('#notice').datagrid({
		url : listUrl,
		toolbar: '#tb',
		fit : true,
		fitColumns : true,
		border : true,
		pagination : true,
		idField : 'id',
		pageSize : config.pageSize,
		autoRowHeight : 140,
		pageList : config.pageList,
		queryParams : {
			termId: $("#termId").val(),
			monthDate: $("#monthDate").datebox('getValue'),
			grade: $("#grade").val(),
			clazz: $("#clazz").val(),
			userName: $("#userName").val(),
			subjectId: $("#subjectId").val()
		},
		nowrap : true,
		striped : true,
		rownumbers : true,
		columns : [ [
		{ 
			field : 'termName',
			title : '学期',
			width : 20,
			resizable : true,
			align : "center"
		}, 
		{
			field : 'gradeText',
			width : 10,
			title : '年级',
			align : "center"
		}, 
		{
			field : 'subjectText',
			width : 10,
			title : '学科',
			align : "center"
		}, 
		{
			field : 'targetName',
			width : 10,
			title : '被评教师',
			align : "center"
		},
		{
			field : 'judgeType',
			title : '评价类别',
			width : 20,
			align : "center"
		},
		{
			field : 'judgeContent',
			title : '评价内容',
			width : 10,
			align : "center"
		},
		{
			field : 'score',
			title : '加减分',
			width : 20,
			align : "center"
		},
		{
			field : 'judgeDepart',
			title : '评价部门',
			width : 10,
			align : "center"
		},
		{
			field : 'judgeTeacher',
			title : '评价人',
			width : 10,
			align : "center"
		},
		{
			field : 'createTime',
			title : '评价日期',
			width : 10,
			align : "center",
			formatter:function(value,row,index){
				return getTime(value, 'yyyy-MM-dd hh:mm:ss');
			}
		}
	  ]]
	});
}

function initTermList(){
    $.ajax({
        url: termListUrl,
        type: 'POST',
        dataType: 'json',
        error : function(data) {
            $.messager.progress('close');
            $.messager.alert('系统提示', data.msg, 'error');
        },
        success: function (data) {
        	var html = "";
        	for(var i in data) {
        		html += "<option value='"+data[i].id+"'>"+data[i].termName+"</option>";
        	}
            $("#termId").html(html);
            loadData();
        }
    });
}

function initGradeList() {
	$.ajax({
 		url : basePath + "/gradeList",
 		type : "post",
 		dataType : "json",
 		async : false,
 		success : function(data) {
 			var html = '<option value="">请选择</option>';
 			for(var i in data){
 		        if (data.hasOwnProperty(i)) {
 		        	html += "<option value='"+i+"'>"+data[i]+"</option>";
 		        };
 		    }
 			$("#grade").html(html);
 		}, error:function(){
 			alert("删除照片异常");
  		}
    });
}

function initSubjectList() {
	$.ajax({
 		url : basePath + "/subjectList",
 		type : "post",
 		dataType : "json",
 		async : false,
 		success : function(data) {
 			var html = '<option value="">请选择</option>';
 			for(var i in data){
 		        if (data.hasOwnProperty(i)) {
 		        	html += "<option value='"+i+"'>"+data[i]+"</option>";
 		        };
 		    }
 			$("#subjectId").html(html);
 		}, error:function(){
 			alert("删除照片异常");
  		}
    });
}

function initDatebox() {
	var currTime=new Date();
    var strDate=currTime.getFullYear() + '-' + (currTime.getMonth()+1)+"-01";
    $('#monthDate').datebox({formatter:function(date){
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? '0' + m : m;
        return y.toString() + '-' + m.toString();
    },parser:function(date){
        console.log(date);
        if (date) {
            return new Date(String(date).substring(0, 4) + '-'
                    + String(date).substring(5,7));
        } else {
            return new Date();
        }
    }});
    $('#monthDate').datebox('setValue',strDate);//默认加载当前月份
}
function reload() {
	dataGrid.datagrid("clearSelections");
	searchForm("searchForm");
}

function searchForm(formId) {
	loadData();
}
function resetForms(formId) {
	$("#" + formId)[0].reset();
	var currTime=new Date();
    var strDate=currTime.getFullYear() + '-' + (currTime.getMonth()+1);
	$("#monthDate").datebox('setValue', strDate);
}

function exportToExcel(searchForm,exportUrl) {
	$("#" + searchForm).attr('action',exportUrl);
	$("#" + searchForm).submit();  
}

